<template>
  <div class="personSelect-container">
    <commonSelect ref="commonSelectRef" :placeholder="placeholder" v-model:modelValue="modelVal" :multiple="multiple" :clearable="clearable"
      :title="title" :authorityList="authorityList" :disabled="disabled" :selectType="selectType"
      :choosePerson="choosePerson" :comUse="comUse" :showInput="showInput" :isReturnData="isReturnData" :isPage="isPage"
      @change="handelChange" :organizeType="organizeType" :displayFormat="displayFormat" :formatRuleData="formatRuleData" :isAutoImport="isAutoImport"
      :isAutoSortOrder="isAutoSortOrder"/>
  </div>
</template>

<script lang="ts">
import commonSelect from "../common/commonSelect/index2.vue"
export default {
  name: "personSelect",
  inject: {
    elForm: {
      default: "",
    },
    elFormItem: {
      default: "",
    },
  },
  components: { commonSelect },
  props: {
    allCompany: {
      type: Boolean,
      default: false,
    },
    department: {
      type: Boolean,
      default: false,
    },
    modelValue: {
      default: () => [],
    },
    placeholder: {
      type: String,
      default: "请选择",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    multiple: {
      type: Boolean,
      default: false,
    },
    collapseTags: {
      type: Boolean,
      default: false,
    },
    clearable: {
      type: Boolean,
      default: false,
    },
    auth: {
      type: Boolean,
      default: false,
    },
    isOnlyOrg: {
      type: Boolean,
      default: false,
    },
    size: String,
    currOrgId: {
      default: "0",
    },
    parentId: {
      default: "",
    },
    // 是否将dialog平铺展示，作为div插入到页面中
    isPage: {
      type: Boolean,
      default: false,
    },
    title: {
      default: "选择组织",
    },
    tenantOrganize: {
      // 租户组织
      type: Boolean,
      default: false,
    },
    // 选择人员
    choosePerson: {
      type: String,
      default: 'all',
    },
    // 用户权限 可选值：department group role post relativePost
    authorityList: {
      type: Array,
      default: () => [],
    },
    selectType: {
      type: String,
      default: "all",
    },
    // 是否展示input输入框
    showInput: {
      type: Boolean,
      default: true,
    },
    // 返回数据类型是否为对象数组[{}],否则为['']
    isReturnData: {
      type: Boolean,
      default: false,
    },
    //组织类型 unit仅单位、department仅部门、object仅项目、all全部
    organizeType: {
      type: String,
      default: "all",
    },
    //显示格式 organizePath组织全路径、name当前名称
    displayFormat: {
      type: String,
      default: "name",
    },
    //返回数据格式 ['返回字段']
    formatRuleData: {
      type: Array,
      default: () => [],
    },
    // 组件使用方式 vForm
    comUse: {
      type: String,
      default: "vForm",
    },
    // 是否自动带入
    isAutoImport: {
      type: Boolean,
      default: false,
    },
    // 人员是否自动排序
    isAutoSortOrder: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      defaultProps: {
        children: "children",
        label: "fullName",
        isLeaf: "isLeaf",
      },
      hasSys: false,
      isAsync: false,
    };
  },
  computed: {
    modelVal: {
      get() {
        return this.modelValue
      },
      set(value) {
        this.$emit('update:modelValue', value)
      },
    },
  },
  methods: {
    handelChange(selectedIds, selectedData) {
      //vform使用数组包对象 ===> 整个数据格式都需要,用于数据返显
      this.$emit('change', selectedIds, selectedData)
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-select {
  position: relative;
}

::v-deep .el-select__tags {
  position: absolute;
  // max-width: inherit !important;
}

.personSelect-container {
  width: 100%;
  height: 100%;
  .el-select__tags {
    max-height: 8rem;
    overflow: auto;

    .el-tag {
      max-width: 260px;
      word-break: break-all;
      height: fit-content;
      white-space: pre-wrap;
    }
  }
}
</style>